<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
        function createCode() {
            var email = $("#email").val();
            if (undefined == email || "" == email) {
                alert("请填写邮箱")
                return
            }

            $("#btn").attr("disabled", "disabled");
            setTimeout(function () {
                btn.disabled = '';
            }, 60 * 1000);//60秒后才能点击

            $.ajax({
                url: "http://localhost:9002/api/code/create/" + email,    //请求的url地址
                type: "GET",   //请求方式
                success: function (req) {
                    if (req) {
                        alert("发送成功");
                    } else {
                        alert("发送失败");
                    }
                },
                error: function () {
                    alert("服务器异常");
                }
            });
        }

        function register() {
            var email = $("#email").val();
            var password = $("#password").val();
            var ConfirmPassword = $("#ConfirmPassword").val();
            var code = $("#code").val();

            if (undefined == email || "" == email ||
                undefined == password || "" == password ||
                undefined == ConfirmPassword || "" == ConfirmPassword ||
                undefined == code || "" == code) {
                alert("请填写信息")
                return
            }
            if (password != ConfirmPassword) {
                alert("密码不正确")
                return
            }

            $.ajax({
                url: "http://localhost:9002/api/user/register/" + email + "/" + password + "/" + code,    //请求的url地址
                type: "GET",   //请求方式
                success: function (req) {
                    if ("0" == req) {
                        window.location.href = 'welcome.html';
                    } else {
                        alert(req);
                    }
                }, error: function (msg) {
                    alert(msg.responseText);
                }
            });
        }
    </script>
    <title>注册</title>
</head>
<body>
<form>
    邮箱<input id="email" type="text"/>
    <br/>
    密码<input id="password" type="password"/>
    <br/>
    确认密码<input id="ConfirmPassword" type="password"/>
    <br/>
    验证码<input id="code" type="text"/><input type="button" value="获取验证码" id="btn" onclick="createCode()"/>
    <br/>
    <button type="button" onclick="register()">注册</button>
</form>
<a href="login.html">登录</a>
</body>
</html>